<?php

namespace SampleFactory;


class Client
{
    public static function main()
    {
        // create product A
        $product_a = SampleFactory::create('ProductA');
        $product_a->display();

        // create product B
        $product_b = SampleFactory::create('ProductB');
        $product_b->display();
    }
}

interface Product
{
    public function display(): void;
}

class ProductA implements Product
{

    public function display(): void
    {
        echo 'product A description.', PHP_EOL;
    }
}

class ProductB implements Product
{

    public function display(): void
    {
        echo 'product B description.', PHP_EOL;
    }
}

class SampleFactory
{

    public static function create(string $name): Product
    {
        $product = null;
        switch ($name) {
            case 'ProductA';
                $product = new ProductA();
                break;
            case 'ProductB';
                $product = new ProductB();
                break;
            default:
                break;
        }
        return $product;
    }
}


Client::main();

